package com.lsh.oms.core.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

/**
 * @author xuanqun
 * @date 2016/12/2
 */
@Slf4j
public class ShopCheckUtils {

    public static boolean checkMarketInfo4Position(String addressInfo) {

        try {
            JSONObject object = JSON.parseObject(addressInfo);

            String province = object.getString("province");
            String city = object.getString("city");
            String county = object.getString("county");
            String address = object.getString("address");
            String realPosition = object.getString("real_position");
            String transLimit = object.getString("trans_limit");
            String contactName = object.getString("contact_name");
            String contactPhone = object.getString("contact_phone");
            if (StringUtils.isAnyEmpty(province, city, county, address, realPosition, transLimit, contactName, contactPhone)) {
                return false;
            }
            JSONObject position = JSON.parseObject(realPosition).getJSONObject("position");
            if (StringUtils.isEmpty(position.toJSONString())) {
                return false;
            }
            String lng = position.getString("lng");
            String lat = position.getString("lat");
            if (StringUtils.isAnyEmpty(lng, lat)) {
                return false;
            }

            return true;
        } catch (Exception ex) {
            log.error("地址信息解析错误", ex);
            return false;
        }

    }

}
